<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author LYS
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <!--        <a-button type="primary" @click="handleForm({})" v-auth="'cardd:yfgz:carddYfgz:edit'">-->
        <!--          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}-->
        <!--        </a-button>-->
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ id: record.id })">
          {{ record.jbgzRymc }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup name="ViewsCarddYfgzCarddYfgzList">
  import { unref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicColumn, BasicTable, useTable } from '/@/components/Table';
  import { carddYfgzDelete, carddYfgzListData } from '/@/api/cardd/yfgz/carddYfgz';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('cardd.yfgz.carddYfgz');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('应发工资管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      // {
      //   label: t('人员名称'),
      //   field: 'jbgzRymc',
      //   component: 'TreeSelect',
      //   componentProps: {
      //     api: officeTreeData,
      //     params: { isLoadUser: true, userIdPrefix: '' },
      //     canSelectParent: false,
      //     allowClear: true,
      //   },
      // },
      {
        label: t('日期'),
        field: 'yfgzRq',
        component: 'DatePicker',
        componentProps: {
          picker: 'month',
          format: 'YYYY-MM',
          valueFormat: 'YYYY-MM',
        },
      },
      {
        label: t('人员名称'),
        field: 'jbgzRymc',
        component: 'Input',
      },
      {
        label: t('状态'),
        field: 'status',
        component: 'Select',
        componentProps: {
          dictType: 'sys_search_status',
          allowClear: true,
          onChange: handleSuccess,
        },
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('日期'),
      dataIndex: 'yfgzRq',
      key: 'a.yfgz_rq',
      sorter: true,
      width: 80,
      align: 'left',
    },
    {
      title: t('人员'),
      dataIndex: 'jbgzRymc',
      key: 'a.jbgz_rymc',
      sorter: true,
      width: 80,
      align: 'left',
      slot: 'firstColumn',
    },
    {
      title: t('基本工资'),
      dataIndex: 'jbgzJbgz',
      key: 'a.jbgz_jbgz',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('缴费基数'),
      dataIndex: 'jbgzJfjs',
      key: 'a.jbgz_jfjs',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('养老保险个人'),
      dataIndex: 'jbgzYlbxgryj',
      key: 'a.jbgz_ylbxgryj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('养老保险单位'),
      dataIndex: 'jbgzYlbxdwyj',
      key: 'a.jbgz_ylbxdwyj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('养老保险小计'),
      dataIndex: 'jbgzYlbxxj',
      key: 'a.jbgz_ylbxxj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('失业险个人'),
      dataIndex: 'jbgzSyxgryj',
      key: 'a.jbgz_syxgryj',
      sorter: true,
      width: 105,
      align: 'right',
    },
    {
      title: t('失业险单位'),
      dataIndex: 'jbgzSyxdwyj',
      key: 'a.jbgz_syxdwyj',
      sorter: true,
      width: 105,
      align: 'right',
    },
    {
      title: t('失业险小计'),
      dataIndex: 'jbgzSyxxj',
      key: 'a.jbgz_syxxj',
      sorter: true,
      width: 105,
      align: 'right',
    },
    {
      title: t('工伤保险个人'),
      dataIndex: 'jbgzGsbxgryj',
      key: 'a.jbgz_gsbxgryj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('工伤保险单位'),
      dataIndex: 'jbgzGsbxdwyj',
      key: 'a.jbgz_gsbxdwyj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('工伤保险小计'),
      dataIndex: 'jbgzGsbxxj',
      key: 'a.jbgz_gsbxxj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('基本医疗个人'),
      dataIndex: 'jbgzJbylgryj',
      key: 'a.jbgz_jbylgryj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('基本医疗单位'),
      dataIndex: 'jbgzJbyldwyj',
      key: 'a.jbgz_jbyldwyj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('基本医疗小计'),
      dataIndex: 'jbgzJbylxj',
      key: 'a.jbgz_jbylxj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('大额医疗补助个人'),
      dataIndex: 'jbgzDeylbzgryj',
      key: 'a.jbgz_deylbzgryj',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('大额医疗补助单位'),
      dataIndex: 'jbgzDeylbzdwyj',
      key: 'a.jbgz_deylbzdwyj',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('大额医疗补助小计'),
      dataIndex: 'jbgzDeylbzxj',
      key: 'a.jbgz_deylbzxj',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('生育保险个人'),
      dataIndex: 'jbgzSybxgryj',
      key: 'a.jbgz_sybxgryj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('生育保险单位'),
      dataIndex: 'jbgzSybxdwyj',
      key: 'a.jbgz_sybxdwyj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('生育保险小计'),
      dataIndex: 'jbgzSybxxj',
      key: 'a.jbgz_sybxxj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('个人应缴合计'),
      dataIndex: 'jbgzGryjhj',
      key: 'a.jbgz_gryjhj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('单位应缴合计'),
      dataIndex: 'jbgzDwyjhj',
      key: 'a.jbgz_dwyjhj',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('合计'),
      dataIndex: 'jbgzHj',
      key: 'a.jbgz_hj',
      sorter: true,
      width: 70,
      align: 'right',
    },
    {
      title: t('全勤奖'),
      dataIndex: 'jbgzQqj',
      key: 'a.jbgz_qqj',
      sorter: true,
      width: 80,
      align: 'right',
    },
    {
      title: t('电话补贴'),
      dataIndex: 'jbgzDhbt',
      key: 'a.jbgz_dhbt',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('交通补贴'),
      dataIndex: 'jbgzJtbt',
      key: 'a.jbgz_jtbt',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('洗车补贴'),
      dataIndex: 'jbgzXcbt',
      key: 'a.jbgz_xcbt',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('无违章投诉补贴'),
      dataIndex: 'jbgzWwztsbt',
      key: 'a.jbgz_wwztsbt',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('更新时间'),
      dataIndex: 'updateDate',
      key: 'a.update_date',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('备注'),
      dataIndex: 'remarks',
      key: 'a.remarks',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('状态'),
      dataIndex: 'status',
      key: 'a.status',
      sorter: true,
      width: 100,
      align: 'center',
      dictType: 'sys_search_status',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        icon: 'i-clarity:note-edit-line',
        title: t('编辑应发工资'),
        onClick: handleForm.bind(this, { id: record.id }),
        auth: 'cardd:yfgz:carddYfgz:edit',
      },
      {
        icon: 'i-ant-design:delete-outlined',
        color: 'error',
        title: t('删除应发工资'),
        popConfirm: {
          title: t('是否确认删除应发工资'),
          confirm: handleDelete.bind(this, record),
        },
        auth: 'cardd:yfgz:carddYfgz:edit',
      },
    ],
  };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload }] = useTable({
    api: carddYfgzListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const params = { id: record.id };
    const res = await carddYfgzDelete(params);
    showMessage(res.message);
    handleSuccess(record);
  }

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
